Skip to content

feat: add map height legend to Tools > Units > Altitude#1423

Open
Avengium wants to merge 7 commits intoAzgaar:masterfrom
Avengium:Altitude-legend
Open

feat: add map height legend to Tools > Units > Altitude#1423
Avengium wants to merge 7 commits intoAzgaar:masterfrom
Avengium:Altitude-legend

Conversation

@Avengium
Copy link
Copy Markdown
Contributor

@Avengium Avengium commented May 7, 2026

Description

A new button has been added to the altitude settings section that displays a visual legend. This legend helps users interpret the different elevation levels represented on the map.

Changes:

UI: A "View Legend" button has been added to Tools > Units > Altitude.

Component: New map legend pop-up that displays the color scale and its corresponding altitude values.

Logic: The legend chooses some representative points. Also updates the unit system that is shown (meters/feet).

How to test:
Go to the side menu and select Tools. Enter Units and then Altitude. Click it and confirm that the legend matches the colors displayed on the map. Switch from meters to feet and verify that the legend values ​​update correctly.

Screenshot

FMG altitude legend 2026-05-07
FMG-altitude-legend-2026-05-07-01jpg

Avengium added 2 commits May 7, 2026 19:26
Added a button on tools > units > altitude that shows a legend for different heights on the map.
@netlify
Copy link
Copy Markdown

netlify Bot commented May 7, 2026

Deploy Preview for afmg ready!

Name Link
🔨 Latest commit 6e7a5b8
🔍 Latest deploy log https://app.netlify.com/projects/afmg/deploys/69ff6c6370f753000889ed16
😎 Deploy Preview https://deploy-preview-1423--afmg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Azgaar
Copy link
Copy Markdown
Owner

Azgaar commented May 7, 2026

For water we can show depth, like we do in Cell Details dialog.

@Azgaar
Copy link
Copy Markdown
Owner

Azgaar commented May 7, 2026

For the button - please just add it to other buttons at the bottom for now.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a “View Legend” control under Tools → Units → Altitude to show an on-map legend intended to help interpret the heightmap’s elevation colors, and updates legend contents when altitude exponent changes.

Changes:

  • Add a new “Height legend” button to the Units Editor (Altitude section) in src/index.html.
  • Wire up the button in public/modules/ui/units-editor.js to toggle a legend and generate representative height samples + labels.
  • Refresh the legend when the altitude exponent slider changes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
src/index.html Adds the “Height legend” UI button in the Altitude (Units Editor) section.
public/modules/ui/units-editor.js Adds legend toggle + legend generation logic and refresh behavior tied to altitude exponent changes.

Comment thread src/index.html
</slider-input>
</div>

<div data-tip="Toggle altitude legend. Granularity affects the amount of heights shown">
Comment thread src/index.html

<div data-tip="Toggle altitude legend. Granularity affects the amount of heights shown">
<span>Height legend:</span>
<button id="altitudeLegend" data-tip="Click to show the altitude legend" class="icon-list-bullet"></button>
Comment thread public/modules/ui/units-editor.js Outdated
Comment thread public/modules/ui/units-editor.js Outdated
Comment thread public/modules/ui/units-editor.js Outdated
Comment on lines +143 to +146
const heightUnitName =
heightUnitSelect.value === "custom_name"
? heightUnitSelect.nextElementSibling?.value || ""
: (heightUnitSelect.selectedOptions[0]?.text.match(/\(([^)]+)\)/)?.[1] ?? "");
Comment thread public/modules/ui/units-editor.js Outdated
Comment on lines +166 to +172
const data = sampled.map(c => [rn(c.height, 0), c.color, rn(c.altitude, 1)]);

// Set the number of items per column
styleLegendColItems.value = data.length;

drawLegend(`Heights (in ${heightUnitName})`, data);

Comment on lines +168 to +172
// Set the number of items per column
styleLegendColItems.value = data.length;

drawLegend(`Heights (in ${heightUnitName})`, data);

Comment on lines 68 to 72
function changeHeightExponent() {
calculateTemperatures();
if (layerIsOn("toggleTemperature")) drawTemperature();
updateLegendIfVisible();
}
Comment thread public/modules/ui/units-editor.js Outdated
Comment thread public/modules/ui/units-editor.js Outdated
As suggested by Copilot.
Read the current heightmap scheme from the same source used by drawHeightmap (e.g., terrs.select(...).attr("scheme") or the style control) and pass it to getColorScheme.
So the colors used to represent different heights update with different style presets.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Avengium
Copy link
Copy Markdown
Contributor Author

Avengium commented May 8, 2026

I don't know how to do any of these suggestions. Reading the comments, it seems there are many things I haven't considered. If anyone wants to carry out this PR, go ahead.

Avengium added 3 commits May 9, 2026 13:58
Deleted manual legend repositioning that overrides fitLegendBox() behavior.
On: public/modules/ui/editors.js
Cached the height counts/levels and only recompute the parts that depend on the exponent/unit.
* Labels now use the same calculation/conversion used by getHeight.
* Ocean height display correctly.
* legend has the unit close to each legend item.
@Avengium
Copy link
Copy Markdown
Contributor Author

Avengium commented May 9, 2026

For water we can show depth, like we do in Cell Details dialog.

Done. With the new commit, ocean depth is measured too. And changes in units are updated.


For the button - please just add it to other buttons at the bottom for now.

Don't you think it makes more sense to keep the altitude button in the altitude section? Maybe putting it some pixels to the right, so it follows the indentation style.

Or would you prefer it to appear as a general feature unrelated to altitude?
I ask because if you change the altitude exponent or the altitude units, it changes in the legend.

I also planned to add a "slider" where the user can introduce the "amount" of representative heights the user can see on the legend (the amount of legend items). But the current option of a fixed "10 items" is fine too. Because there are only these colors.

@Avengium
Copy link
Copy Markdown
Contributor Author

Avengium commented May 9, 2026

To find out what still needs updating, could you collapse the Copilot comments that have already been resolved and run Copilot again to check for any comments that still need to be implemented?

When changing the Height unit (m/ft/f), the legend also refreshes by doing that.
Without needing to delete and invoke the legend again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants